package blog.controller;

import blog.common.Result;
import blog.entity.VideoType;

import blog.service.VideoTypeService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/videoType")
@Slf4j
public class VideoTypeController {
    @Autowired
    private VideoTypeService videoTypeService;

    /**
     * 获取所有视频类型
     * @return
     * http://localhost:8080/videoType?page=1&pageSize=10
     */
    @GetMapping
    public Result getAllVideoType(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        //1.判断参数是否合法
        if (page < 1 || pageSize < 1){
            return Result.error("参数不合法");
        }
        //2.调用service层的方法
        Page<VideoType> userPage = new Page<>(page, pageSize);
        LambdaQueryWrapper<VideoType> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(VideoType::getCreateTime);
        Page<VideoType> userPage1 = videoTypeService.page(userPage, wrapper);
        //3.返回结果
        return Result.success(userPage1, "查询成功");

    }












}